#include <stdio.h>
#include <stdint.h>
#include "simple_uart.h"
#include "iic_comm_firmware.h"



#define devname "/dev/ttyS4"


void msg_send(uint8_t *buf, uint32_t len) {
    simple_uart_send(buf, len);
    printf("send len %d\n", len);
}


uint8_t rbuf[100];
int main(void) {
    int32_t rlen = 0;
    uint32_t idx = 0;
    simple_uart_init(devname, 115200);
    firmware_file_check();
    while(1) {
        rlen = simple_uart_rec(rbuf, 100);
        if(rlen > 0) {
            printf("rec %d\n", rlen);
            if(rlen == 4) {
                //msg_handle(rbuf, (uint32_t)rlen);
                idx = *((uint32_t*)rbuf);
                printf("idx is %d\r\n", idx);
                save_slave_firmware_ack(idx);
            }
        }
        usleep(10*1000);
        slave_firmware_loop(msg_send);
        usleep(200*1000);
    }

}




